package com.yanqu.road.server.cmd.chefduel.process1;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChefDuelPhase1Proto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.chefduel.ChefDuelPhase1Module;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CHEF_DUEL1_MAKE_MODIFY,desc = "厨神对决一阶段改装")
public class ChefDuelPhase1ModifyCmd extends AbstractCommand {

    private int activityId;

    private int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        ChefDuelPhase1Proto.ChefDuelPhase1ModifyReq req = ChefDuelPhase1Proto.ChefDuelPhase1ModifyReq.parseFrom(packet.getBytes());

        activityId = req.getActivityId();

        type = req.getType();

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(ChefDuelPhase1Module.class).makeModify(activityId, type);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            ChefDuelPhase1Proto.ChefDuelPhase1ModifyResp.Builder builder = ChefDuelPhase1Proto.ChefDuelPhase1ModifyResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_CHEF_DUEL1_MAKE_MODIFY,builder);

        }
    }
}
